package com.xuelang.pipeline.client.application.enums;

import com.xuelang.pipeline.client.task.enums.TaskInstanceCodeEnum;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>组件编程语言枚举</p>
 *
 * @author : yixin.lys
 * @date : 2024-08-26 15:12
 **/
@Getter
public enum ProgramLanguageEnum {

    NODE_JS("nodejs"),
    JAVA("java"),
    GO("go"),
    PYTHON("python");

    private String value;

    ProgramLanguageEnum(String value){
        this.value = value;
    }

    // 创建一个静态映射，将字符串值映射到对应的枚举
    private static final Map<String, ProgramLanguageEnum> VALUE_MAP = new HashMap<>();

    // 静态初始化块，将所有枚举值放入映射中
    static {
        for (ProgramLanguageEnum language : ProgramLanguageEnum.values()) {
            VALUE_MAP.put(language.getValue(), language);
        }
    }

    // 静态方法，将字符串值转换为对应的枚举
    public static ProgramLanguageEnum fromValue(String value) {
        ProgramLanguageEnum language = VALUE_MAP.get(value.toLowerCase());
        if (language == null) {
            throw new IllegalArgumentException("未知的编程语言: " + value);
        }
        return language;
    }

    // 根据编程语言获取对应的 image 枚举
    public TaskInstanceCodeEnum getImageEnum() {
        switch (this) {
            case NODE_JS:
                return TaskInstanceCodeEnum.NODEJS_IMAGE;
            case JAVA:
                return TaskInstanceCodeEnum.JAVA_IMAGE;
            default:
                return null;
        }
    }

}
